import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt

df1 = pd.DataFrame({'city':['北京','上海','广州','深圳','杭州','厦门'],'price': [62428,53950,31375,57259,30447,37539]})
df2 = pd.DataFrame({'city':['北京','上海','广州','深圳','杭州','厦门','南京'],'population_density': [1267,3814,1760,6889,8268,2078,1103]})
df3 = pd.merge(df1,df2,on='city')
print(df3)


df4 = pd.merge(df2,df1,how='left',on='city')
print(df4)

df5 = pd.merge(df1,df2,how='right',on='city')
print(df5)

# df5.dropna(inplace=True)
# print(df5)
# df5.plot(x='population_density',y='price')
# plt.show()

df6 = df1.set_index('city').join(df2.set_index('city'))
print(df6)

df7 = df1.set_index('city').join(df2.set_index('city'),how='right',rsuffix='_2')
print(df7)

df8 = pd.DataFrame({'city':['西安','太原'],'price': [14211,11748]})
df9 = pd.concat([df1,df8])
print(df9)

df10 = pd.concat([df1,df2],axis=1)
print(df10)

# df_bj = pd.read_csv('bj.csv')
# print(df_bj.head())